#include"Info.h"
#include<stdio.h>
#include<stdbool.h>
#include<stdlib.h>
#include<string.h>



struct INFO
{   
    char*num;
    char*name;
    
};

IN* InitIn(const char*num,const char* name)        //初始化 通讯录里的联系人  包括号码和姓名
{
    IN* i = (IN*)malloc(sizeof(IN));
    if( i == NULL)
    {
        printf("InitIn i malloc 申请失败！\n");
        return NULL;
    }
    i->num = strdup(num);
    i->name = strdup(name);
    return i;
}



void FreeIn(void*ptr)
{
    IN*i = (IN*)ptr;
    free(i->num);
    free(i->name);
    free(i); 
}

void PrintIn(void*ptr)
{
    IN*i = (IN*)ptr;
    printf("%s %s\n",i->num,i->name);
}


bool IsEqualByName(void*p1,void*p2)
{
    IN* i = (IN*)p1;
    const char*name = (const char*)p2;
    return strcmp(i->name,name) == 0;
}

bool IsEqualByNum(void*p1,void*p2)
{
    IN* i = (IN*)p1;
    const char*num = (const char*)p2;
    return strcmp(i->num,num) == 0;
}

bool ByNum(void*p1,void*p2)
{
    IN* i1 = (IN*)p1;
    IN* i2 = (IN*)p2;
    return strcmp(i1->num,i2->num) == 0;
}

bool ByName(void*p1,void*p2)
{
    IN* i1 = (IN*)p1;
    IN* i2 = (IN*)p2;
    return strcmp(i1->name,i2->name) == 0;
}